package com.ruoyi.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.ProductTest;
import com.ruoyi.system.mapper.ProductTestMapper;
import com.ruoyi.system.service.IProductTestService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;

/**
 * 产品testService业务层处理
 *
 * @author ruoyi
 */
@RequiredArgsConstructor
@Service
public class ProductTestServiceImpl implements IProductTestService {

    private final ProductTestMapper baseMapper;

    /**
     * 查询产品test
     *
     * @param id 产品testID
     * @return 产品test
     */
    @Override
    public ProductTest selectProductTestById(Long id) {
        return baseMapper.selectById(id);
    }

    /**
     * 查询产品test列表
     *
     * @param productTest 产品test
     * @return 产品test
     */
    @Override
    public TableDataInfo<ProductTest> selectPageProductTestList(ProductTest productTest, PageQuery pageQuery) {
        LambdaQueryWrapper<ProductTest> lqw = buildQueryWrapper(productTest);
        Page<ProductTest> page = baseMapper.selectPage(pageQuery.build(), lqw);
        return TableDataInfo.build(page);
    }

    /**
     * 查询产品test列表
     *
     * @param productTest 产品test
     * @return 产品test
     */
    @Override
    public List<ProductTest> selectProductTestList(ProductTest productTest) {
        LambdaQueryWrapper<ProductTest> lqw = buildQueryWrapper(productTest);
        return baseMapper.selectList(lqw);
    }

    private LambdaQueryWrapper<ProductTest> buildQueryWrapper(ProductTest productTest) {
        LambdaQueryWrapper<ProductTest> lqw = Wrappers.lambdaQuery();
        lqw.like(StringUtils.isNotBlank(productTest.getName()), ProductTest::getName, productTest.getName());
        lqw.like(StringUtils.isNotBlank(productTest.getAlias()), ProductTest::getAlias, productTest.getAlias());
        return lqw;
    }

    /**
     * 新增产品test
     *
     * @param productTest 产品test
     * @return 结果
     */
    @Override
    public int insertProductTest(ProductTest productTest) {
        return baseMapper.insert(productTest);
    }

    /**
     * 修改产品test
     *
     * @param productTest 产品test
     * @return 结果
     */
    @Override
    public int updateProductTest(ProductTest productTest) {
        return baseMapper.updateById(productTest);
    }

    /**
     * 批量删除产品test
     *
     * @param ids 需要删除的产品testID
     * @return 结果
     */
    @Override
    public int deleteProductTestByIds(Collection<Long> ids) {
        return baseMapper.deleteBatchIds(ids);
    }

    /**
     * 删除产品test信息
     *
     * @param id 产品testID
     * @return 结果
     */
    @Override
    public int deleteProductTestById(Long id) {
        return baseMapper.deleteById(id);
    }
} 